import type { EnterpriseUserBase, PaginationType } from "@/types"
import { reactive, ref } from "vue"
import type { OrganizationOptionType } from "../types"

export default function usePageState() {
  const loading = ref(false)

  const searchForm = reactive({
    name: '',
    email: '',
    orgId: null,
    role: '',
    status: ''
  })

  const pagination = reactive<PaginationType>({
    current: 1,
    size: 10,
    total: 0
  })

  const organizationList = ref<OrganizationOptionType[]>([
    { id: 1, name: '阿里巴巴集团' },
    { id: 2, name: '腾讯科技' },
    { id: 3, name: '字节跳动' }
  ])

  const tableData = ref<EnterpriseUserBase[]>([
    {
      id: 1,
      name: '张三',
      email: 'zhangsan@alibaba.com',
      avatar: '',
      orgId: 1,
      orgName: '阿里巴巴集团',
      role: 'Admin',
      status: 'active',
      createdAt: '2024-01-15T10:30:00',
      lastLoginAt: '2024-01-20T09:15:00'
    },
    {
      id: 2,
      name: '李四',
      email: 'lisi@tencent.com',
      avatar: '',
      orgId: 2,
      orgName: '腾讯科技',
      role: 'Recruiter',
      status: 'active',
      createdAt: '2024-01-16T14:20:00',
      lastLoginAt: '2024-01-19T16:30:00'
    }
  ])

  const getRoleName = (role: string): string => {
    const roleMap: Record<string, string> = {
      'Admin': '企业管理员',
      'Recruiter': '企业HR'
    }
    return roleMap[role] || role
  }

  const getRoleTagType = (role: string): string => {
    const typeMap: Record<string, string> = {
      'Admin': 'danger',
      'Recruiter': 'warning'
    }
    return typeMap[role] || 'info'
  }

  const formatDate = (dateString: string): string => {
    return new Date(dateString).toLocaleString('zh-CN')
  }
  return {
    loading,
    searchForm,
    pagination,
    organizationList,
    tableData,
    getRoleName,
    getRoleTagType,
    formatDate
  }
}
